package com.dong.message.service.impl;

import com.dong.message.bean.Message;
import com.dong.message.mq.MQProvider;
import com.dong.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.dong.message.service.MessageSend;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageSend messageSend;
    @Autowired
    MQProvider mqProvider;

    @Value("${send.type}")
    Integer type;

    public Message makeMessage(){
        return new Message().bulider().setMsgId(1).setType("SMS").setProvider("SMSMessageProvider");
    }

    public void send(){
        //1、取出定义好的消息
        //2、根据配置决定是中间件发送还是本地编码发送
        if (type==1){
            mqProvider.push(makeMessage());
        }else {
            messageSend.send(makeMessage());
        }
    }
}
